/*
 * This file is part of jboss-admin-rest
 * Copyright 2009, Christos Vasilakis (cvasilak@gmail.com)
 * 
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

package org.jboss.admin.rest.domain.common;

import org.jboss.managed.api.ManagedProperty;
import org.jboss.managed.api.annotation.ViewUse;

import javax.xml.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@XmlRootElement(name = "properties")
@XmlAccessorType(XmlAccessType.NONE)
@XmlType(propOrder = {"configuration", "runtime", "statistic"})
public class ManagedPropertiesBean {

	/* ViewUse.CONFIGURATION properties */
	private List<ManagedPropertyBean> listConfig = new ArrayList<ManagedPropertyBean>();
	
	/* ViewUse.RUNTIME properties */
	private List<ManagedPropertyBean> listRuntime = new ArrayList<ManagedPropertyBean>();

	/* ViewUse.STATISTICS properties */
	private List<ManagedPropertyBean> listStatistics = new ArrayList<ManagedPropertyBean>();
	
	public ManagedPropertiesBean() {
	}
	
	public ManagedPropertiesBean(Map<String, ManagedProperty> map) {
		for (ManagedProperty property : map.values()) {
	
			if (property.hasViewUse(ViewUse.CONFIGURATION)) {
				listConfig.add(new ManagedPropertyBean(property));
			} else if (property.hasViewUse(ViewUse.RUNTIME)) {
				listRuntime.add(new ManagedPropertyBean(property));
			} else if (property.hasViewUse(ViewUse.STATISTIC)) {
				listStatistics.add(new ManagedPropertyBean(property));
			}
		}
	}

	@XmlElementWrapper(name = "configuration")
	@XmlElement(name = "property")
	public List<ManagedPropertyBean> getConfiguration() {
		return listConfig;
	}
	
	@XmlElementWrapper(name = "runtime")
	@XmlElement(name = "property")
	public List<ManagedPropertyBean> getRuntime() {
		return listRuntime;
	}
	
	@XmlElementWrapper(name = "statistic")
	@XmlElement(name = "property")
	public List<ManagedPropertyBean> getStatistic() { 
		return listStatistics;
	}
}
